package com.learn.geoquiz

import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.Button
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    // 1. 定义两个按钮变量
    private lateinit var trueButton: Button
    private lateinit var falseButton: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        setTitle(R.string.app_name)

        // 2. 通过资源ID访问视图对象
        trueButton = findViewById(R.id.true_button)
        falseButton = findViewById(R.id.false_button)

        trueButton.setOnClickListener { view: View ->
            // 3.1 处理true按钮的点击事件
            // 在 高版本的Android系统中，setGravity() 方法被弃用，
            val toast = Toast.makeText(this, R.string.correct_toast, Toast.LENGTH_SHORT)
            toast.setGravity(Gravity.TOP or Gravity.START, 50, 100)
            toast.show()
        }

        falseButton.setOnClickListener { view: View ->
            // 3.2 处理false按钮的点击事件
            val toast = Toast.makeText(this, R.string.incorrect_toast, Toast.LENGTH_SHORT)
            toast.setGravity(Gravity.CENTER, 10, 10)
            toast.show()
        }
    }
}